package com.woniuxy.pxxt.common.exception;

import com.woniuxy.pxxt.common.result.Result;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 全局异常处理
 * <P> Date: 2022/2/27:15:54
 * <P> Description:
 */
@ControllerAdvice
public class GlobalExceptionHandler  {


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result Error(Exception e){

        e.printStackTrace();

        if(e instanceof UnauthorizedException){
            return Result.fail().message("你没有操作权限");
        }
        return Result.fail().message(e.getMessage());
    }
}
